home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
graphics
/
mfpic
/
alfatest
/
mfpic.tex
< prev
next >
Wrap
Text File
|
1994-08-11
|
15KB
|
545 lines
%%%
%%% File: mfpic.tex
%%%
% preliminary version of macros.
\chardef\oldatcatcode=\catcode`@
\catcode`@=11
\immediate\write16
{mfpic version 0.2.9 alpha Thu 11 August 1994}
% local declarations:
\wlog {mfpic: local declarations}
\newwrite\@outx
\newread\@graphx
\newcount\@gcode
\newbox\@labeledgraph
\newbox\@temp
\wlog {mfpic: internal dimension parameters}
\newdimen\@graphwd
\newdimen\@graphleft
\newdimen\@graphht
\newdimen\@graphdp
\newdimen\@centerskip
\newdimen\@labeltemp
\def\do@ptparam#1#2{%
\def\@ptparami[##1]{\csname#1\endcsname[##1]}%
\def\@ptparamii{\csname#1\endcsname[#2]}%
\def\@ptparamiii{%
\ifx[\nchr \expandafter\@ptparami
\else \expandafter\@ptparamii\fi}%
\futurelet\nchr\@ptparamiii}
% dimension parameters:
\wlog {mfpic: user's dimension parameters}
\newdimen\mfpicunit
\mfpicunit=1pt
\newdimen\pointsize
\newif\ifpointfilled\pointfilledtrue
\newdimen\shadespace
\newdimen\hatchspace
\newdimen\headlen
\newdimen\axisheadlen
\newdimen\hashlen
\newdimen\dashlen
\newdimen\dashspace
% default settings:
\pointsize=2pt
\shadespace=1pt
\hatchspace=3pt
\headlen=3pt
\axisheadlen=5pt
\hashlen=4pt
\dashlen=4pt
\dashspace=4pt
% standard setting macros:
\def\darkershade{%
\multiply\shadespace by 5
\divide\shadespace by 6}
\def\lightershade{%
\multiply\shadespace by 6
\divide\shadespace by 5}
\def\dashlineset{%
\dashlen=4pt
\dashspace=4pt}
\def\dotlineset{%
\dashlen=1pt
\dashspace=2pt}
% direct output to Metafont file:
\def\mfcmd#1{%
\immediate\write\@outx{#1}%
\ignorespaces}
% pen size setting:
\def\@pickup{%
\mfcmd{pickup pencircle scaled penwd;}}
\def\pen#1{%
\mfcmd{interim penwd:=#1;}
\@pickup}
% arrowhead shape setting:
\def\headshape#1#2#3{%
\mfcmd{%
interim hdwdr:=#1;
interim hdten:=#2;
hfilled:=#3;}}
% Prefix commands:
% routines to select drawing (of paths) :
\newif\if@drawing\@drawingtrue
\newif\if@path\@pathfalse
\newif\if@dodraw\@dodrawtrue
\newif\if@connect\@connectfalse
\newif\if@doconnect\@doconnectfalse
\def\@doreset{%
\@dodrawtrue
\if@connect
\@drawingfalse
\@pathtrue
\@doconnecttrue
\else
\@drawingtrue
\@pathfalse
\@doconnectfalse
\fi
\ignorespaces}
\def\@checkpath#1#2{%
\if@drawing
\if@path
\mfcmd{#1}%
\else
\mfcmd{#2}%
\fi
\fi}
\def\@draw#1{%
\@checkpath{drawnpath}{safedraw}%
\mfcmd{\if@connect\else ( \fi
\if@doconnect transformed ztr)--( \fi #1
\if@connect \else ) transformed ztr; \fi}%
\@doreset}
% store following mfpic path in MF path variable #1:
\def\store#1{\@mfcmd{path #1; #1:=}\@drawingfalse}
% shading, hatching, filling, and erasing:
\def\@shade[#1]{\mfcmd{shadepath(#1)}\@drawingfalse}
\def\shade{\do@ptparam{@shade}{\the\shadespace}}
\def\@hatch[#1]{\mfcmd{hatchpath(#1)}\@drawingfalse}
\def\hatch{\do@ptparam{@hatch}{\the\hatchspace}}
\def\fill{\mfcmd{safefill}\@drawingfalse}
\def\white{\mfcmd{safeunfill}\@drawingfalse}
% arrowheads:
\def\@arrow{%
\@checkpath{}{trash:=}%
\mfcmd{headpath(\@hlength,\@hrotate,\@hbackset)}%
\@pathtrue}
\def\@checkchar#1#2{%
\ifx#1l\gdef\@hlength{#2}\else
\ifx#1r\gdef\@hrotate{#2}\else
\ifx#1b\gdef\@hbackset{#2}\fi\fi\fi}
\def\@arrowthree[#1#2]{\@checkchar{#1}{#2}\@arrow}
\def\@arrowtwo[#1#2]{%
\@checkchar{#1}{#2}%
\do@ptparam{@arrowthree}{WW}}
\def\@arrowone[#1#2]{%
\gdef\@hlength{\the\headlen}%
\gdef\@hrotate{0}%
\gdef\@hbackset{0pt}%
\@checkchar{#1}{#2}%
\do@ptparam{@arrowtwo}{ZZ}}
\def\arrow{\do@ptparam{@arrowone}{YY}}
% outline, dotted lines, and closed paths:
\def\draw{%
\if@dodraw\@checkpath{}{trash:=}%
\mfcmd{drawnpath}\fi
\@drawingfalse\@dodrawfalse}
\def\@dotted[#1,#2]{%
\if@dodraw\@checkpath{}{trash:=}%
\mfcmd{dotted(#1,#2)}\fi
\@drawingfalse\@dodrawfalse}
\def\dotted{%
\do@ptparam{@dotted}%
{\the\dashlen,\the\dashspace}}
\def\closed{\@checkpath{drawnpath}{safedraw}%
\mfcmd{closedpath}%
\@pathtrue
\if@drawing\@dodrawfalse\fi
\@drawingfalse}
\def\bclosed{\@checkpath{drawnpath}{safedraw}%
\mfcmd{bclosedpath}%
\@pathtrue
\if@drawing\@dodrawfalse\fi
\@drawingfalse}
\def\sclosed{\@checkpath{drawnpath}{safedraw}%
\mfcmd{sclosedpath}%
\@pathtrue
\if@drawing\@dodrawfalse\fi
\@drawingfalse}
\def\cbclosed{\@checkpath{drawnpath}{safedraw}%
\mfcmd{cbclosedpath}%
\@pathtrue
\if@drawing\@dodrawfalse\fi
\@drawingfalse}
% reversing orientation of paths:
\def\reverse{\@checkpath{drawnpath}{safedraw}%
\mfcmd{\if@doconnect transformed ztr)--(\fi reverse}%
\@doconnectfalse
\@pathtrue
\if@drawing\@dodrawfalse\fi
\@drawingfalse}
% connecting open figures:
\def\connect{\@checkpath{drawnpath}{safedraw}%
\mfcmd{(}%
\bgroup
\@connecttrue\@doconnectfalse
\if@drawing\@dodrawfalse\fi
\@drawingfalse}
\def\endconnect{%
\mfcmd{) transformed ztr;}%
\@doconnectfalse\@connectfalse
\egroup
\@doreset}
% rotating a path:
\def\rotate#1{%
\@checkpath{drawnpath}{safedraw}%
\mfcmd{rotatedpath(#1)}%
\@pathtrue
\if@drawing\@dodrawfalse\fi
\@drawingfalse}
% Affine transforms of the MF _coordinate system_ :
% grouping macros that enable nested coordinate systems:
\def\coords{\mfcmd{bcoords;}}%
\def\endcoords{\mfcmd{ecoords;}}%
% macro that applies a nominated MF affine transformer:
\def\applyT#1{\mfcmd{apply_t(#1);}}%
% specific transform macros for MF coordinates;
% see _The METAFONTbook_ for most of these.
\def\rotates#1{\applyT{rotated #1}}% degrees
\def\rotatesaround#1#2{\applyT{rotatedaround(#1,#2)}}% point, degrees.
\def\reflectsabout#1#2{\applyT{reflectedabout(#1,#2)}}% line #1 -- #2.
\def\shifts#1{\applyT{shifted #1}}% pair.
\def\scales#1{\applyT{scaled #1}}% same scaling in X and Y directions.
\def\xscales#1{\applyT{xscaled #1}}% scale only X.
\def\yscales#1{\applyT{yscaled #1}}% scale only Y.
\def\zscales#1{\applyT{zscaled #1}}% complex multiplication of points.
\def\xslants#1{\applyT{xslanted #1}}% skew in X direction by a multiple of Y coord.
\def\yslants#1{\applyT{yslanted #1}}% skew in Y direction by a multiple of X coord.
\def\zslants#1{\applyT{zslanted #1}}% see `graphbase.mf'.
\def\xyswaps#1{\applyT{xyswapped #1}}% reflect in line Y=X.
\def\boosts#1{\applyT{boosted #1}}% special relativity boost.
% end Prefix commands.
% open and close MF graphs file:
\def\opengraphsfile#1{%
\@gcode=0
\immediate\openout\@outx=#1.mf
\openin\@graphx=#1.tfm
\ifeof\@graphx
\immediate\write16
{No file #1.tfm.}%
\font\@graph=dummy\relax
\else
\font\@graph=#1\relax
\fi
\closein\@graphx
\immediate\write16
{mfpic: Don't forget to process #1.mf!}%
\immediate\write16
{ Then reprocess this file.}%
\mfcmd{if unknown mode: mode:= localfont; fi}%
\mfcmd{if unknown mag: mag:=\number\mag/1000; fi}%
\mfcmd{if unknown graphbase: input graphbase; fi}%
\mfcmd{gcode:=\number\@gcode;}%
% set global defaults:
\headshape{1}{1}{false}%
\mfcmd{interim penwd:=0.5pt;}%
\mfcmd{}}
\def\closegraphsfile{%
\mfcmd{}%
\mfcmd{end.}%
\immediate\closeout\@outx}
% percent and sharp signs for MF file:
\def\mf@gobble#1{}
\def\mf@p{\expandafter\mf@gobble\string\%}
\def\mf@s{\expandafter\mf@gobble\string\#}
% for reading \@mfpic:
\global\font\@tcurr=\fontname\font\relax
\nullfont
% beginning mfpic environment:
\def\@mfpic#1#2#3#4#5#6%
{%
% set up TeX
\leavevmode
\bgroup
\parfillskip0pt plus1fill
% conversion (local) :
\def\@xconv##1{%
\global\advance##1 by -#3\mfpicunit
\global ##1 = #1 ##1}%
\def\@yconv##1{%
\global\advance##1 by -#5\mfpicunit
\global ##1 = -#2 ##1}%
% set up graph box:
\global\advance\@gcode1
\global\@graphwd=#4\mfpicunit
\@xconv\@graphwd
\@graphht=#6\mfpicunit
\@yconv\@graphht
\@graphleft=0pt
\@graphdp=0pt
\global\setbox\@labeledgraph=
\vtop{\noindent\@graph\char\@gcode}%
% set up Metafont file:
\mfcmd{}%
\mfcmd{unitlen:=\the\mfpicunit\mf@s;}%
\mfcmd{xscale:=#1*unitlen; yscale:=#2*unitlen;}%
\mfcmd{xneg:=#3; xpos:=#4;}%
\mfcmd{yneg:=#5; ypos:=#6;}%
\mfcmd{beginchar
(incr gcode,
(xpos-xneg)*xscale,
(ypos-yneg)*yscale,
0);}%
\mfcmd{initpic;}%
% the (MF based) drawing macros:
% Metafont title
\def\mftitle##1{%
\mfcmd{"##1";}}
% allow MF path ##1 to be shaded, connected, etc:
\def\mfobj##1{\@draw{##1}}%
% axes and axis Marks:
\def\@axes[##1]{%
\mfcmd{axes(##1);}\@doreset}%
\def\axes{\do@ptparam{@axes}{\the\axisheadlen}}%
\def\@xmarks[##1]##2{%
\mfcmd{xmarks(##1,##2);}\@doreset}%
\def\xmarks{\do@ptparam{@xmarks}{\the\hashlen}}%
\def\@ymarks[##1]##2{%
\mfcmd{ymarks(##1,##2);}\@doreset}%
\def\ymarks{\do@ptparam{@ymarks}{\the\hashlen}}%
% points:
\def\@point[##1]##2{%
\if@connect
\lines{##2}%
\else
\mfcmd{pointd(##1,\ifpointfilled true\else false\fi,##2);}%
\fi
\@doreset}%
\def\point{\do@ptparam{@point}{\the\pointsize}}%
% polylines:
\def\lines##1{%
\@draw{(curve(false, false) ##1)}}%
% curves:
\def\curve##1{%
\@draw{(curve(true,false) ##1)}}%
% cyclic curves:
\def\cyclic##1{%
\@draw{(curve(true,true) ##1)}}%
% open quadratic B-splines
\def\qspline##1{%
\@draw{openqbs(##1)}}
% closed quadratic B-splines
\def\closedqspline##1{%
\@draw{closedqbs(##1)}}
% open cubic B-splines
\def\cspline##1{%
\@draw{opencbs(##1)}}
% closed cubic B-splines
\def\closedcspline##1{%
\@draw{closedcbs(##1)}}
% upright rectangles:
\def\rect##1{%
\@draw{rect(##1)}}%
% circles and ellipses:
\def\circle##1{%%
\@draw{circle(##1)}}%
\def\@ellipse[##1]##2{%
\@draw{ellipse(##2,##1)}}%
\def\ellipse{\do@ptparam{@ellipse}{0}}%
% circular arcs:
\def\@arc[##1]##2{%
\if##1s\@draw{(arcpps(##2))}\else
\if##1p\@draw{(arcplr(##2))}\else
\if##1c\@draw{(arccps(##2))}\else
\@draw{(arcppp(##2))}\fi\fi\fi}%
\def\arc{\do@ptparam{@arc}{s}}%
% polar coordinates:
\def\@plrpoint[##1]##2{%
\if@connect
\plrlines{##2}%
\else
\mfcmd{plrpointd(##1,%
\ifpointfilled true\else false\fi,%
##2);}%
\fi
\@doreset}%
\def\plrpoint{\do@ptparam{@plrpoint}{\the\pointsize}}%
\def\plrlines##1{%
\@draw{(plrcurve(false,false) ##1)}}%
\def\plrcurve##1{%
\@draw{(plrcurve(true,false) ##1)}}%
\def\plrcyclic##1{%
\@draw{(plrcurve(true,true) ##1)}}%
% modified polar coordinates:
\def\turtle##1{%
\@draw{(turtle(##1))}}%
\def\wedge##1{%
\@draw{(wedge(##1))}}%
% functions:
\def\@function[##1]##2##3{%
\@draw{(function(%%
\if##1s true\else false\fi, ##2, ##3))}}%
\def\function{\do@ptparam{@function}{s}}%
\def\@parafcn[##1]##2##3{%
\@draw{(parafcn(
\if##1s true\else false\fi, ##2, ##3))}}%
\def\parafcn{\do@ptparam{@parafcn}{s}}%
\def\@plrfcn[##1]##2##3{%
\@draw{(plrfcn(
\if##1s true\else false\fi, ##2, ##3))}}%
\def\plrfcn{\do@ptparam{@plrfcn}{s}}%
\def\@btwnfcn[##1]##2##3##4{%
\@draw{((function(
\if##1s true\else false\fi, ##2, ##3))
--(reverse function(
\if##1s true\else false\fi, ##2, ##4))
--cycle)}}%
\def\btwnfcn{\do@ptparam{@btwnfcn}{p}}%
\def\@plrregion[##1]##2##3{%
\@draw{(plrfcn(
\if##1s true\else false\fi, ##2, ##3)
--(0,0)--cycle)}}%
\def\plrregion{\do@ptparam{@plrregion}{p}}%
% end of (MF based) drawing macros.
% (TeX based) labels and caption:
% Labels:
\def\@label[##1##2](##3,##4)##5{%
% compute width of graph with label,
% and reset size if necessary:
\setbox\@temp=\hbox{##5}%
% stretch graph rightwards:
\@labeltemp=##3\mfpicunit
\@xconv\@labeltemp
\if##2l\advance\@labeltemp by \wd\@temp\else
\if##2c\advance\@labeltemp by 0.5\wd\@temp\fi\fi
\ifdim\@labeltemp>\@graphwd
\global\@graphwd=\@labeltemp\fi
% stretch graph leftwards:
\@labeltemp=##3\mfpicunit
\@xconv\@labeltemp
\if##2r\advance\@labeltemp by -\wd\@temp\else
\if##2c\advance\@labeltemp by -0.5\wd\@temp\fi\fi
\ifdim\@labeltemp<\@graphleft
\global\@graphleft=\@labeltemp\fi
% stretch graph upwards:
\@labeltemp=##4\mfpicunit
\@yconv\@labeltemp
\if##1b\advance\@labeltemp by \ht\@temp\else
\if##1c\advance\@labeltemp by 0.5\ht\@temp\fi\fi
\ifdim\@labeltemp>\@graphht
\global\@graphht=\@labeltemp\fi
% stretch graph downwards:
\@labeltemp=##4\mfpicunit
\@yconv\@labeltemp
\if##1t\advance\@labeltemp by -\dp\@temp\else
\if##1c\advance\@labeltemp by -0.5\dp\@temp\fi\fi
\ifdim\@labeltemp<\@graphdp
\global\@graphdp=\@labeltemp\fi
% set label onto picture:
\global\setbox\@labeledgraph =
\vtop{\unvbox\@labeledgraph
\vbox to0pt{%
\if##1c\kern-0.5\ht\@temp\else
\if##1b\kern-\ht\@temp\fi\fi
\@labeltemp=##4\mfpicunit
\@yconv\@labeltemp
\kern\@labeltemp
\hbox{%
\@labeltemp=##3\mfpicunit
\@xconv\@labeltemp
\kern\@labeltemp
\if##2c\kern-0.5\wd\@temp\else
\if##2r\kern-\wd\@temp\fi\fi
\box\@temp}%
\vss}%
\nointerlineskip}%
\ignorespaces
}% -- end \@label
\def\label{\do@ptparam{@label}{bl}}%
% Caption:
% \@docaption (called by \endmfpic) :
\def\@docaption{\global\@graphleft=0pt\relax}%
\def\@caption[##1,##2]##3%
{%
% redefine \@docaption to set caption:
\def\@docaption
{%
% compute adjustments to center:
\setbox\@temp =
\hbox\bgroup ##3\egroup
\ifdim\wd\@temp>##1\@graphwd
\setbox\@temp =
\hbox
\bgroup
\tolerance=500\relax
\vbox{%
\hsize=##2\@graphwd
\noindent ##3}%
\egroup
\fi
\@centerskip=\@graphwd
\advance\@centerskip -\wd\@temp
\divide\@centerskip by 2
% set caption onto picture:
\global\setbox\@labeledgraph =
\vbox{%
% check if caption's wider than graph:
\ifdim\@centerskip<0pt%
\@graphleft = -\@centerskip
\moveright -\@centerskip\fi
\vbox
\bgroup
\unvbox\@labeledgraph
\medskip
\hbox{%
\noindent
\kern\@centerskip
\box\@temp}%
\egroup
\vss}%
}% -- end \@docaption.
\ignorespaces
}% -- end \@caption.
\def\caption{\do@ptparam{@caption}{1.2,1.0}}%
% end of object macros.
\ignorespaces
}% -- end \@mfpic.
% restore font after reading \@mfpic.
\@tcurr
% setting up optional arguments:
\def\@pici[#1]#2#3#4#5{\@mfpic{\@param}{#1}{#2}{#3}{#4}{#5}}
\def\mfpic[#1]{%
\def\@param{#1}%
\do@ptparam{@pici}{#1}}
% ending mfpic environment:
\def\endmfpic{%
\global\advance\@graphwd by -\@graphleft
\global\setbox\@labeledgraph =
\vbox
{%
\hbox to \@graphwd
{%
\kern-\@graphleft
\box\@labeledgraph
% \vrule height\@graphht depth-\@graphdp width 0pt
\hss
}% end hbox.
\vss
}% end vbox.
\mfcmd{endchar;}%
\@docaption
\advance\@graphwd by \@graphleft
\hbox to\@graphwd
{%
\kern\@graphleft
\box\@labeledgraph
\hss
}% end hbox.
\egroup
}% -- end \endmfpic.
\catcode`@=\oldatcatcode
%%%
%%% end mfpic.tex
%%%